<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计费后台管理</title>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/managercss.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/wbox.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/wbox.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/validate.js"></script>
<script type="text/javascript">
<!--
	var wBox;
	$(function(){
		$(".list div").mousemove(function(){
			$(this).css("background","#E3EEFF");
		}).mouseout(function(){
			$(this).css("background","");
		});
		$("#addProduct").click(function(){
			var htmlStr = "<form id=\"addForm\" class=\"democss\"><table>";
			htmlStr += "<tr><th>机型名称:</th><td><input type=\"text\" name=\"productName\" id=\"productName\" size=30 /></td></tr>";
			htmlStr += "<tr><th></th><td><input type=\"button\" value=\"添加\" class=\"submit\" onclick=\"add();\"/></td></tr>";
			htmlStr += "</table></form>";
			wBox=$("#pop").wBox({
				title: "添加新的产品",
				html: htmlStr
			});
			wBox.showBox();
		});
	});

	function add(){
		var productName = $("#productName").val();
		if(isNull(productName)){
			alert("请输入产品名称!");
			$("#productName").focus();
			return;
		}else{
			var date = $("#addForm").formSerialize();
			$.ajax({
				url:"<%=request.getContextPath()%>/admin/product/add",
				data:date,
				type:"POST",
				success:function(flag){
					if(flag=='1'){
						alert("添加成功!");
						wBox.close();
						window.location.href="<%=request.getContextPath() %>/admin/product";
					}else{
						alert("添加失败!");
					}
				}
			});
		}
	}


	function del(productId){
		if(confirm("你确认删除该产品吗?")){
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/product/del/"+productId,
				type:"GET",
				success:function(flag){
					if(flag=='1'){
						alert("删除成功!");
						window.location.href="<%=request.getContextPath() %>/admin/product";
					}else{
						alert("删除失败!");
					}
				}
			});
		}
	}

	function updateShow(productId,productName){
		var htmlStr = "<form id=\"updateForm\" class=\"democss\"><table>";
		htmlStr += "<tr><th>机型名称:</th><td><input type=\"text\" name=\"productName\" id=\"productName\" value=\""+productName+"\" size=30 /></td></tr>";
		htmlStr += "<tr><th></th><td><input type=\"button\" value=\"修改\" class=\"submit\" onclick=\"update();\"/></td></tr>";
		htmlStr += "<input type=\"hidden\" name=\"productId\" id=\"productId\" value=\""+productId+"\" />";
		htmlStr += "</table></form>";
		wBox=$("#pop").wBox({
			title: "修改产品",
			html: htmlStr
		});
		wBox.showBox();
	}

	function update(companyId){
		var productName = $("#productName").val();
		if(isNull(productName)){
			alert("请输入产品名称!");
			$("#productName").focus();
			return;
		}else{
			var date = $("#updateForm").formSerialize();
			$.ajax({
				url:"<%=request.getContextPath() %>/admin/product/update",
				data:date,
				type:"POST",
				success:function(flag){
					if(flag=='1'){
						alert("修改成功!");
						wBox.close();
						window.location.href="<%=request.getContextPath() %>/admin/product";
					}else{
						alert("修改失败!");
					}
				}
			});
			return;
		}
	}

	function addBilling(productId){
		wBox = $("#ajax").wBox({
			requestType: "iframe",
			iframeWH:{width:900,height:500},
			target:"<%=request.getContextPath() %>/admin/billing/addUI?productId="+productId,
			title: "配置计费点"
		});
		wBox.showBox();
	}
//-->
</script>
</head>
<body>
<div class="information">
	<div class="title">
		产品管理
	</div>
	<div class="listTitle">
		<ul>
			<li style="width:40px;">编号</li>
			<li style="width:200px;">产品名称</li>		
			<li style="width:150px;">创建时间</li>
			<li style="width:150px;">操作</li>
		</ul>
		<div class="clear"></div>
	</div>
	<div class="list">
		<c:forEach items="${pageBean.result}" var="product" varStatus="status">
			<div class="${status.index%2==0?'noselect':'select' }">
				<ul>
					<li style="width:40px;">${product.productId }</li>
					<li style="width:200px;">${product.productName }</li>		
					<li style="width:150px;">${product.createTime }</li>
					<li style="width:150px;">
						<a href="#" onclick="del('${product.productId }')">删除</a>
						<a href="#" onclick="updateShow('${product.productId }','${product.productName }')">修改</a>
						<a href="#" onclick="addBilling('${product.productId}')">配置计费点</a>
					</li>
				</ul>
				<div class="clear"></div>
			</div>
		</c:forEach>
	</div>
	<jsp:include page="../page.jsp" flush="true"></jsp:include>
	<div class="search">
		<input type="button" name="addProduct" id="addProduct" value="添加新的产品==>>" />
	</div>
</div>
</body>
</html>